{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "sys.version_info(major=3, minor=4, micro=3, releaselevel='final', serial=0)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import sys\n",
    "sys.version_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1.1.0.dev0'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import petl as etl\n",
    "etl.__version__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class='petl'>\n",
       "<thead>\n",
       "<tr>\n",
       "<th>foo</th>\n",
       "<th>bar</th>\n",
       "<th>baz</th>\n",
       "</tr>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style='text-align: right'>81</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.025010755222666936</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>35</td>\n",
       "<td>pears</td>\n",
       "<td style='text-align: right'>0.22321073814882275</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>94</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.6766994874229113</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>69</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.5904925124490397</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>4</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.09369523986159245</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "<p><strong>...</strong></p>"
      ],
      "text/plain": [
       "+-----+----------+----------------------+\n",
       "| foo | bar      | baz                  |\n",
       "+=====+==========+======================+\n",
       "|  81 | 'apples' | 0.025010755222666936 |\n",
       "+-----+----------+----------------------+\n",
       "|  35 | 'pears'  |  0.22321073814882275 |\n",
       "+-----+----------+----------------------+\n",
       "|  94 | 'apples' |   0.6766994874229113 |\n",
       "+-----+----------+----------------------+\n",
       "|  69 | 'apples' |   0.5904925124490397 |\n",
       "+-----+----------+----------------------+\n",
       "|   4 | 'apples' |  0.09369523986159245 |\n",
       "+-----+----------+----------------------+\n",
       "..."
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tbl = etl.dummytable(10, seed=42)\n",
    "tbl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class='petl'>\n",
       "<thead>\n",
       "<tr>\n",
       "<th>foo</th>\n",
       "<th>bar</th>\n",
       "<th>baz</th>\n",
       "</tr>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style='text-align: right'>81</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.025010755222666936</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>35</td>\n",
       "<td>pears</td>\n",
       "<td style='text-align: right'>0.22321073814882275</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "<p><strong>...</strong></p>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "tbl.display(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class='petl'>\n",
       "<thead>\n",
       "<tr>\n",
       "<th>foo</th>\n",
       "<th>bar</th>\n",
       "<th>baz</th>\n",
       "</tr>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style='text-align: right'>81</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.025010755222666936</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>35</td>\n",
       "<td>pears</td>\n",
       "<td style='text-align: right'>0.22321073814882275</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>94</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.6766994874229113</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>69</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.5904925124490397</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>4</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.09369523986159245</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>29</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.561245062938613</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>91</td>\n",
       "<td>oranges</td>\n",
       "<td style='text-align: right'>0.2204406220406967</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>75</td>\n",
       "<td>bananas</td>\n",
       "<td style='text-align: right'>0.8094304566778266</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>0</td>\n",
       "<td>pears</td>\n",
       "<td style='text-align: right'>0.6981393949882269</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>43</td>\n",
       "<td>bananas</td>\n",
       "<td style='text-align: right'>0.15547949981178155</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "tbl.displayall()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class='petl'>\n",
       "<thead>\n",
       "<tr>\n",
       "<th>foo</th>\n",
       "<th>bar</th>\n",
       "<th>baz</th>\n",
       "</tr>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style='text-align: right'>81</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.025010755222666936</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>35</td>\n",
       "<td>pears</td>\n",
       "<td style='text-align: right'>0.22321073814882275</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>94</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.6766994874229113</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>69</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.5904925124490397</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>4</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.09369523986159245</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "<p><strong>...</strong></p>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<table class='petl'>\n",
       "<thead>\n",
       "<tr>\n",
       "<th>0|foo</th>\n",
       "<th>1|bar</th>\n",
       "<th>2|baz</th>\n",
       "</tr>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style='text-align: right'>81</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.025010755222666936</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>35</td>\n",
       "<td>pears</td>\n",
       "<td style='text-align: right'>0.22321073814882275</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>94</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.6766994874229113</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>69</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.5904925124490397</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>4</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.09369523986159245</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "<p><strong>...</strong></p>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "tbl.display()\n",
    "tbl.display(index_header=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class='petl'>\n",
       "<caption>example data</caption>\n",
       "<thead>\n",
       "<tr>\n",
       "<th>foo</th>\n",
       "<th>bar</th>\n",
       "<th>baz</th>\n",
       "</tr>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style='text-align: right'>81</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.025010755222666936</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>35</td>\n",
       "<td>pears</td>\n",
       "<td style='text-align: right'>0.22321073814882275</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>94</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.6766994874229113</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>69</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.5904925124490397</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>4</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.09369523986159245</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "<p><strong>...</strong></p>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "tbl.display(caption='example data')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class='petl'>\n",
       "<thead>\n",
       "<tr>\n",
       "<th>foo</th>\n",
       "<th>bar</th>\n",
       "<th>baz</th>\n",
       "</tr>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style='text-align: right'>81</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.025010755222666936</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>35</td>\n",
       "<td>pears</td>\n",
       "<td style='text-align: right'>0.22321073814882275</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>94</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.6766994874229113</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>69</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.5904925124490397</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>4</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.09369523986159245</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "<p>example data</p>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "tbl.display(epilogue='example data')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class='petl'>\n",
       "<thead>\n",
       "<tr>\n",
       "<th>foo</th>\n",
       "<th>bar</th>\n",
       "<th>baz</th>\n",
       "</tr>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style='text-align: right'>81</td>\n",
       "<td>appl</td>\n",
       "<td style='text-align: right'>0.02</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>35</td>\n",
       "<td>pear</td>\n",
       "<td style='text-align: right'>0.22</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>94</td>\n",
       "<td>appl</td>\n",
       "<td style='text-align: right'>0.67</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>69</td>\n",
       "<td>appl</td>\n",
       "<td style='text-align: right'>0.59</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style='text-align: right'>4</td>\n",
       "<td>appl</td>\n",
       "<td style='text-align: right'>0.09</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "<p><strong>...</strong></p>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "tbl.display(truncate=4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class='petl'>\n",
       "<thead>\n",
       "<tr>\n",
       "<th>foo</th>\n",
       "<th>bar</th>\n",
       "<th>baz</th>\n",
       "</tr>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr style='background-color: #faa'>\n",
       "<td style='text-align: right'>81</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.025010755222666936</td>\n",
       "</tr>\n",
       "<tr style='background-color: white'>\n",
       "<td style='text-align: right'>35</td>\n",
       "<td>pears</td>\n",
       "<td style='text-align: right'>0.22321073814882275</td>\n",
       "</tr>\n",
       "<tr style='background-color: #faa'>\n",
       "<td style='text-align: right'>94</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.6766994874229113</td>\n",
       "</tr>\n",
       "<tr style='background-color: #faa'>\n",
       "<td style='text-align: right'>69</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.5904925124490397</td>\n",
       "</tr>\n",
       "<tr style='background-color: white'>\n",
       "<td style='text-align: right'>4</td>\n",
       "<td>apples</td>\n",
       "<td style='text-align: right'>0.09369523986159245</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "<p><strong>...</strong></p>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "tbl.display(tr_style=lambda row: 'background-color: %s' % ('#faa' if row.foo > 50 else 'white'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class='petl'>\n",
       "<thead>\n",
       "<tr>\n",
       "<th>foo</th>\n",
       "<th>bar</th>\n",
       "<th>baz</th>\n",
       "</tr>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr style='font-size: .8em'>\n",
       "<td style='text-align: right'>81</td>\n",
       "<td style='background-color: yellow'>apples</td>\n",
       "<td style='background-color: #aaf'>0.025010755222666936</td>\n",
       "</tr>\n",
       "<tr style='font-size: .8em'>\n",
       "<td style='text-align: right'>35</td>\n",
       "<td style='background-color: yellow'>pears</td>\n",
       "<td style='background-color: #aaf'>0.22321073814882275</td>\n",
       "</tr>\n",
       "<tr style='font-size: .8em'>\n",
       "<td style='text-align: right'>94</td>\n",
       "<td style='background-color: yellow'>apples</td>\n",
       "<td style='background-color: #faa'>0.6766994874229113</td>\n",
       "</tr>\n",
       "<tr style='font-size: .8em'>\n",
       "<td style='text-align: right'>69</td>\n",
       "<td style='background-color: yellow'>apples</td>\n",
       "<td style='background-color: #faa'>0.5904925124490397</td>\n",
       "</tr>\n",
       "<tr style='font-size: .8em'>\n",
       "<td style='text-align: right'>4</td>\n",
       "<td style='background-color: yellow'>apples</td>\n",
       "<td style='background-color: #aaf'>0.09369523986159245</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "<p><strong>...</strong></p>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "tbl.display(tr_style='font-size: .8em',\n",
    "            td_styles={'bar': 'background-color: yellow',\n",
    "                       'baz': lambda v: 'background-color: %s' % ('#faa' if v > .5 else '#aaf')})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(('name', 'id'),\n",
       " ('Արամ Խաչատրյան', 1),\n",
       " ('Johann Strauß', 2),\n",
       " ('Вагиф Сәмәдоғлу', 3),\n",
       " ('章子怡', 4),\n",
       " ('Արամ Խաչատրյան', 1),\n",
       " ('Johann Strauß', 2),\n",
       " ('Вагиф Сәмәдоғлу', 3),\n",
       " ('章子怡', 4))"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t = ((u'name', u'id'),\n",
    "     (u'Արամ Խաչատրյան', 1),\n",
    "     (u'Johann Strauß', 2),\n",
    "     (u'Вагиф Сәмәдоғлу', 3),\n",
    "     (u'章子怡', 4),\n",
    "     (u'Արամ Խաչատրյան', 1),\n",
    "     (u'Johann Strauß', 2),\n",
    "     (u'Вагиф Сәмәдоғлу', 3),\n",
    "     (u'章子怡', 4))\n",
    "t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class='petl'>\n",
       "<thead>\n",
       "<tr>\n",
       "<th>name</th>\n",
       "<th>id</th>\n",
       "</tr>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td>Արամ Խաչատրյան</td>\n",
       "<td style='text-align: right'>1</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td>Johann Strauß</td>\n",
       "<td style='text-align: right'>2</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td>Вагиф Сәмәдоғлу</td>\n",
       "<td style='text-align: right'>3</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td>章子怡</td>\n",
       "<td style='text-align: right'>4</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td>Արամ Խաչատրյան</td>\n",
       "<td style='text-align: right'>1</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "<p><strong>...</strong></p>"
      ],
      "text/plain": [
       "+-------------------+----+\n",
       "| name              | id |\n",
       "+===================+====+\n",
       "| 'Արամ Խաչատրյան'  |  1 |\n",
       "+-------------------+----+\n",
       "| 'Johann Strauß'   |  2 |\n",
       "+-------------------+----+\n",
       "| 'Вагиф Сәмәдоғлу' |  3 |\n",
       "+-------------------+----+\n",
       "| '章子怡'             |  4 |\n",
       "+-------------------+----+\n",
       "| 'Արամ Խաչատրյան'  |  1 |\n",
       "+-------------------+----+\n",
       "..."
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tbl2 = etl.wrap(t)\n",
    "tbl2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class='petl'>\n",
       "<caption>unicode example</caption>\n",
       "<thead>\n",
       "<tr>\n",
       "<th>name</th>\n",
       "<th>id</th>\n",
       "</tr>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td>Արամ Խաչատրյան</td>\n",
       "<td style='text-align: right'>1</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td>Johann Strauß</td>\n",
       "<td style='text-align: right'>2</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td>Вагиф Сәмәдоғлу</td>\n",
       "<td style='text-align: right'>3</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td>章子怡</td>\n",
       "<td style='text-align: right'>4</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td>Արամ Խաչատրյան</td>\n",
       "<td style='text-align: right'>1</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "<p><strong>...</strong></p>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "tbl2.display(caption='unicode example')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.4.3+"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
